﻿package mortal.component.gComplexList
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import flash.events.*;
    import mortal.game.view.common.*;

    public class GComplexList extends GSprite
    {
        private var _titleType:Class;
        private var _unfold:GComplexListUnfoldBase;
        private var _titleData:Array;
        private var _selectIndex:int = -1;
        private var _titleUI:Vector.<GComplexListTitleBase>;
        public var titleH:int;
        public var titleGap:int;

        public function GComplexList()
        {
            this._titleUI = new Vector.<GComplexListTitleBase>;
            this.isHideDispose = true;
            return;
        }// end function

        public function set titleType(param1:Class) : void
        {
            this._titleType = param1;
            return;
        }// end function

        public function set unfoldType(param1:Class) : void
        {
            this._unfold = UIFactory.getUICompoment(param1, 0, 0, this);
            return;
        }// end function

        public function get unfold() : GComplexListUnfoldBase
        {
            return this._unfold;
        }// end function

        public function set unfoldData(param1:Object) : void
        {
            this._unfold.data = param1;
            return;
        }// end function

        public function set titleData(param1:Array) : void
        {
            var _loc_3:GComplexListTitleBase = null;
            this.cleanAllTitleUI();
            this._titleData = param1;
            var _loc_2:* = param1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2)
            {
                
                _loc_3 = UIFactory.getUICompoment(this._titleType, 0, 0, this);
                _loc_3.data = param1[_loc_4];
                _loc_3.name = "title_" + _loc_4;
                _loc_3.configEventListener(MouseEvent.CLICK, this.onClick);
                this._titleUI.push(_loc_3);
                _loc_4++;
            }
            return;
        }// end function

        public function get titleData() : Array
        {
            return this._titleData;
        }// end function

        public function set selectIndex(param1:int) : void
        {
            this._selectIndex = param1;
            this.dispatchEvent(new Event(Event.CHANGE));
            return;
        }// end function

        public function get selectIndex() : int
        {
            return this._selectIndex;
        }// end function

        public function drawNow() : void
        {
            var _loc_1:GComplexListTitleBase = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:* = this._titleUI.length;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2)
            {
                
                _loc_1 = this._titleUI[_loc_5] as GComplexListTitleBase;
                if (_loc_5 <= this._selectIndex)
                {
                    _loc_4 = this.titleH * _loc_5 + this.titleGap * _loc_5;
                    if (_loc_5 == this._selectIndex)
                    {
                        TweenMax.to(this._unfold, 0.2, {y:_loc_4});
                    }
                }
                else
                {
                    _loc_4 = this.titleH * _loc_5 + this.titleGap * _loc_5 + this._unfold.height;
                }
                TweenMax.to(_loc_1, 0.2, {y:_loc_4});
                _loc_5++;
            }
            this.addChild(this._unfold);
            return;
        }// end function

        private function onClick(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget.name;
            var _loc_3:* = _loc_2.split("_")[1];
            if (this._selectIndex != _loc_3)
            {
                this.selectIndex = _loc_3;
            }
            return;
        }// end function

        private function cleanAllTitleUI() : void
        {
            var _loc_1:GComplexListTitleBase = null;
            for each (_loc_1 in this._titleUI)
            {
                
                _loc_1.dispose();
            }
            this._titleUI.splice(0, this._titleUI.length);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._selectIndex = -1;
            this.titleH = 0;
            this.titleGap = 0;
            if (this._unfold)
            {
                this._unfold.dispose(param1);
            }
            this.cleanAllTitleUI();
            this._titleType = null;
            this._unfold = null;
            this._titleData = null;
            return;
        }// end function

    }
}
